<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<div class="new"  style="width:100px;height:100px;background-color: #6FA5DB"></div>

<input type="hidden" id="accessToken" value="{$accessToken}">
<script type="text/javascript" src="http://www.youyiku-yishu.cn/Apps/WebApp/View/default/js/test/jquery-1.10.2.min.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>

<script>
    wx.config({
        debug: ture,
        appId: '<?php echo $signPackage["appId"];?>',
        timestamp:'<?php echo $signPackage["timestamp"];?>',
        nonceStr: '<?php echo $signPackage["nonceStr"];?>',
        signature: '<?php echo $signPackage["signature"];?>',
        jsApiList: [
            // 所有要调用的 API 都要加到这个列表中
            'startRecord','stopRecord','translateVoice','uploadVoice','chooseImage','previewImage','uploadImage','getLocalImgData'
        ]
    });
    $('.new').click(function() {

        wx.chooseImage({
            count: 1, // 默认9
            sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
            sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
            success: function (res) {
                var localIds = res.localIds;// 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
                // alert(JSON.stringify(res));
                var access = $('#accessToken').val();
                //images.serverId = [];
                //   alert(2222);

                var ua = navigator.userAgent.toLowerCase();
                if (ua.match(/iphone/i) == "micromessenger") {
                    var ios = true;
                } else {
                    var ios = false;
                }
                if (ios || window.__wxjs_is_wkwebview) { //ios需要进一步处理

                    IosUpload(localIds[0])
                }else{
                    AndroidUpload(localIds[0]);
                }



                function IosUpload(localId){

                    wx.getLocalImgData({
                        localId: localId.toString(),
                        isShowProgressTips: 1,
                        success: function (res) {
                            var localData = res.localData; // localData是图片的base64数据，可以用img标签显示
                            localData = localData.replace('jgp', 'jpeg');
                            $.ajax({
                                type:'POST',
                                url:'http://www.youyiku-yishu.cn/Examine.php',
                                // url: WST.U('WebApp/PhotoBooks/weChatUpload'),

                                data: {'imgData':localData},
                                dataType:'json',
                                success: function (data) {
                                    alert(JSON.stringify(data));

                                }
                            })

                        },
                        fail: function (res) {
                            //alert('该图片暂时无法查看')
                            // console.log(res);
                        }
                    })

                }

                function AndroidUpload(localId){
                    wx.uploadImage({
                        localId: localId.toString(),
                        isShowProgressTips: 1,
                        success: function (res) {

                            // alert(1111);
                            //images.serverId.push(res.serverId);
                            //下载
                            $.ajax({
                                type: 'POST',
                                url: 'http://www.youyiku-yishu.cn/WechatUpload.php',
                                // url: WST.U('WebApp/PhotoBooks/weChatUpload'),
                                data: {'media_id': res.serverId, 'access': access},
                                // data: {'media_id': res.serverId},
                                dataType: 'json',
                                success: function (data) {
                                    // alert(JSON.stringify(data));
                                    var direction=$("#direction").val();
                                    var url=data.filepath;

                                    var pbId=$('#pbId').val();
                                    var page=$('#current_page').val();
                                    // alert(JSON.stringify(data));

                                }
                            })
                        },
                        fail: function (res) {


                        }
                    })
                }


            }
        })
        $('#remove').val(0);
    })






</script>

</body>
</html>